package com.yzc.mihuyou.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yzc.mihuyou.entity.PageWuer;
import com.yzc.mihuyou.entity.User;
import com.yzc.mihuyou.mapper.TopicMapper;
import com.yzc.mihuyou.service.TopicService;
import com.yzc.mihuyou.util.TokenProccessor;
import com.yzc.mihuyou.vo.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.time.Year;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 话题表 前端控制器
 * </p>
 *
 * @author 易紫诚
 * @since 2022-04-28
 */
@RestController
@RequestMapping("/mihuyou/topic")
public class TopicController {

    @Autowired
    TopicService topicService;
    @Autowired
    TokenProccessor tokenProccessor;
    @Autowired
    TopicMapper topicMapper;
    @GetMapping("selPae")
    public JsonResult selPae(int type,Integer i){
        Map<String,Object> map=new HashMap<>();
         map.put("Topic",topicService.selTue(type,i));
        return  new JsonResult(200,"查询成功",map);
    }

    @GetMapping("topicDetail/{id}")
        public  JsonResult topicDetail(@PathVariable("id") int id, int type, PageWuer pageWuer, HttpServletRequest request){
        if(pageWuer.getSize()==null){
            pageWuer.setSize(10L);
        }
        if(pageWuer.getCurrent()==null){
            pageWuer.setCurrent(0L);
        }
        String token = request.getHeader("token");
        User user=null;
        if(token!=null){
            user= tokenProccessor.verify(token);
        }
        Long ids=0L;
        if(user!=null){
            ids=user.getUserId();
        }

        return new JsonResult(200,"查询成功", topicService.selInse(id,type,pageWuer,ids));
    }

    @GetMapping("selTop")
    public  JsonResult selTop(String prue){
        Map<String,Object> map=new HashMap<>();
        map.put("topic",topicService.listTopes(prue));
        return new JsonResult(200,"查询成功",map);
    }

}

